﻿Imports Telerik.Web.UI
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO

Partial Class Voucher
    Inherits System.Web.UI.Page
    Dim _CommandName As String
    Dim _Command As String
    Dim Grid As RadGrid
    Dim VoucherObj As New DBVoucherSP
    Dim VoucherDatatset As New Data.DataSet
    Dim VoucherLinesObj As New DBVoucherLinesSP
    Dim VoucherLinesDatatset As New Data.DataSet
    Dim AccountObj As New AccountsSP
    Dim AccountDataSet As New DataSet
    Dim FilesObj As New DBtblFilesSP
    Dim FilesDatatset As New Data.DataSet
    Public strConnection As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString.ToString
    Dim index As Integer = -1

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Me.Theme = GetGlobalResourceObject("SystemResource", "Theme")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim _lblPageTitle As Label
            _lblPageTitle = Me.Master.FindControl("lblPageTitle")
            _lblPageTitle.Text = GetLocalResourceObject("PageTitle")
        End If
    End Sub


    Private Function InsertUpdateData(ByVal cmd As SqlCommand) As [Boolean]
        Dim con As New SqlConnection(strConnection)
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
        Try
            con.Open()
            cmd.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            Response.Write(ex.Message)
            Return False
        Finally
            con.Close()
            con.Dispose()
        End Try
    End Function

    'Sub ResetControls()

    '    ' Form = EmployeesForm
    '    Grid = rgVoucher

    '    Dim x As Integer = 0

    '    Dim ctr As Control

    '    'For Each ctr In Form.Controls
    '    For Each ctr In pnlVoucher.Controls

    '        If (ctr.[GetType]().ToString() = "Telerik.Web.UI.RadTextBox") Then
    '            CType(ctr, RadTextBox).Text = ""
    '        ElseIf (ctr.[GetType]().ToString() = "Telerik.Web.UI.RadNumericTextBox") Then
    '            CType(ctr, RadNumericTextBox).Text = ""
    '        ElseIf (ctr.[GetType]().ToString() = "ASP.usercontrols_onefiltereddropdownlist_ascx") Then
    '            CType(ctr.FindControl("RadComboBoxDescription"), Telerik.Web.UI.RadComboBox).SelectedIndex = 0
    '        ElseIf (ctr.[GetType]().ToString() = "Telerik.Web.UI.RadComboBox") Then
    '            CType(ctr, RadComboBox).SelectedIndex = 0
    '        ElseIf (ctr.[GetType]().ToString() = "Telerik.Web.UI.RadDatePicker") Then
    '            CType(ctr, RadDatePicker).DbSelectedDate = DBNull.Value
    '        End If

    '    Next

    'End Sub

    Protected Sub rgVoucher_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles rgVoucher.ItemCommand
        _CommandName = e.CommandName

        If rgVoucher.SelectedItems.Count > 0 Then
            'access a string value
            hdnVoucherID.Value = rgVoucher.SelectedValues("ID").ToString()
        End If

        If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
            hdnVoucherID.Value = dataItem.GetDataKeyValue("ID").ToString
        End If
        If e.CommandName = "Add" Then
            e.Canceled = True
            Response.Redirect("VoucherDtl.aspx?VoucherID=")
        ElseIf (e.CommandName = RadGrid.EditCommandName) Then
            Response.Redirect(String.Format("VoucherDtl.aspx?VoucherID={0}", hdnVoucherID.Value))
                End If
    End Sub

End Class

